<?php

namespace App\Remote\AMap;

use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpFoundation\Request as RequestAlias;

class AMapPlaceRemote extends Remote
{
    /**
     * @param string $lnt
     * @param string $lat
     * @param array $types
     * @param int $radius 单位 m
     * @param int $page
     * @param int $pageSize
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function around(string $lnt, string $lat, array $types, int $radius, int $page, int $pageSize)
    {
        return self::customRequestV3(
            "/v3/place/around?" . http_build_query([
                "location"  => "{$lnt},{$lat}",
                "types"     => implode("|", $types),
                "radius"    => $radius,
                "page_size" => $pageSize,
                "page_num"  => $page,
                "key"       => parent::getKey()
            ]),
            RequestAlias::METHOD_GET
        );
    }

    /**
     * @param string $long
     * @param string $lat
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function reGeo(string $long, string $lat)
    {
        return self::customRequestV3(
            "/v3/geocode/regeo?" . http_build_query([
                "location"   => "{$long},{$lat}",
                "output"     => "json",
                "radius"     => 1000,
                "extensions" => "base",
                "key"        => parent::getKey()
            ]),
            RequestAlias::METHOD_GET
        );
    }

    /**
     * @param string $city
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function weatherInfo(string $city)
    {
        return self::customRequestV3(
            "/v3/weather/weatherInfo?" . http_build_query([
                "city" => $city,
                "key"  => parent::getKey()
            ]),
            RequestAlias::METHOD_GET,
            null,
            null,
            null,
            30 * 60
        );
    }
}
